<template>
<div>
    <div >
       <el-button size="small" @click="Addlaber">保存</el-button>
       <el-button size="small" v-if="Yes" @click="examine">提交审批</el-button>
      </div>

    <div >
        <font size="6" bold   style="position:relative;left:700px">劳务实名制</font>
      </div>
      <br>
      
<el-form :model="laber"  label-width="100px" class="demo-ruleForm">
    <!-- 第一个表格 -->
    <table class="divtable" width="100%">
        <tr>
            <td colspan="8" class="color">基本信息</td>
        </tr>
        <tr>
           
            <td class="tabletd">姓名:</td>
            <td><el-input v-model="laber.name"   clearable></el-input></td>
            <td class="tabletd">身份证:</td>
            <td ><el-input v-model="laber.sfz"   clearable></el-input></td>
             <td class="tabletd">工种:</td>
            <td><el-select v-model="laber.profession" clearable>
                     <el-option v-for="t in professions" v-bind:key="t.id" :label="t.profession_name" :value="t.id"></el-option>
                </el-select></td>
             <td class="tabletd">日期:</td>
            <td><el-input type="date" v-model="laber.apply_date"  value-format="yyyy-MM-dd"  ></el-input></td>
        </tr>
        <tr>
            <td class="tabletd">项目名称:</td>
            <td><el-input v-model="laber.p_id" @focus="pid"   clearable></el-input></td>
            <td class="tabletd"></td>
            <td></td>
            <td class="tabletd"></td>
            <td></td>
            <td class="tabletd"></td>
            <td></td>
        </tr>
        <tr>
            <td class="tabletd">工作内容:</td>
            <td colspan="7"><el-input v-model="laber.commit" type="textarea" rows="4"  clearable></el-input></td>
        </tr>
        
    </table>

    <multi-file-upload
                style="width: 100%;margin: 20px auto"
                title="照片"
                action="http://localhost/uploads"
                :params="{folder: 'tenderPurchasePlan'}"
                :headers="{token: token}"
                :show-button="!checkRoute"
                @uploadSuccess="handleUploadSuccess"
                :parent-file-list="fileList"
        ></multi-file-upload>

        <multi-file-upload
                style="width: 100%;margin: 20px auto"
                title="附件"
                action="http://localhost/uploads"
                :params="{folder: 'tenderPurchasePlan2'}"
                :headers="{token: token}"
                :show-button="!checkRoute"
                @uploadSuccess="handleUploadSuccess2"
                :parent-file-list="fileList2"
        ></multi-file-upload>

    
</el-form>
    <!--所属项目子组件-->
<el-dialog  :visible.sync="dialogVisible"  width="50%">
<project-info-list  v-if="dialogVisible"  @row="project"></project-info-list>
</el-dialog>




  </div>
</template>

<script>

import ProjectInfoList from '../common/projectInfo/ProjectInfoList.vue';


import {DateUtil} from "@/model/common/DateUtil";

import LaoWuHeTong from '@/model/smj/LaoWuHeTong'
 const Laowuhetong= new LaoWuHeTong;

import LaoWuShiMingZhi from '@/model/smj/LaoWuShiMingZhi'
const laowushimingzhi = new LaoWuShiMingZhi;

export default {
  name: "LaoWuShiMingZhi",
  components: {ProjectInfoList},
  directives: {},
  data() {
    return {
        laber:{
            apply_date:DateUtil.today(),
        },
        professions:[],
        tenderPurchasePlan: {
            id: '',
            date: DateUtil.today(),
            planEditor: sessionStorage.getItem('realName')
        },
        tenderPurchasePlan2: {
            id: '',
            date: DateUtil.today(),
            planEditor: sessionStorage.getItem('realName')
        },
        fileList:[],
        fileList2:[],
        projectId:'',//所属项目id

        dialogVisible:false,//隐藏子组件

        tenderPurchaseDetails:[],

    }
  },
  mounted() {},
  methods: {

      getprofessions(){
            laowushimingzhi.getprofessions().then((response)=>{
                this.professions = response.data;
            })
      },



      //开启隐藏项目子组件
      pid(){
           this.dialogVisible = true;
      },

      //响应项目组件
      project(row){
            this.laber.p_id = row.projectName;
            this.projectId = row.id;//获取所属项目id
            this.dialogVisible = false;
      },


         //文件上传
        handleUploadSuccess(ids,fileList){
            console.log(fileList)
                this.tenderPurchasePlan.attachemeIds = ids
            },

         handleUploadSuccess2(ids,fileList){
            console.log(fileList)
                this.tenderPurchasePlan2.attachemeIds = ids
            },



     

      //添加劳务合同
      Addlaber(){
          console.log(this.laber)
            //判断合同信息不能为空
          if(this.laber.name == '' || this.laber.name == undefined){
                this.$message.error('错误信息,姓名不能为空');
          }else{
              if(this.laber.sfz == '' || this.laber.sfz == undefined){
                this.$message.error('错误信息,身份证不能为空');
          }else{
              if(this.laber.profession == '' || this.laber.profession == undefined){
                this.$message.error('错误信息,工种不能为空');
          }else{
              if(this.laber.p_id == '' || this.laber.p_id == undefined){
                this.$message.error('错误信息,项目名称不能为空');
          }else{
              if(this.laber.commit == '' || this.laber.commit == undefined){
                this.$message.error('错误信息,工作内容不能为空');
          }else{


                    this.laber.attach_ids=this.tenderPurchasePlan.attachemeIds;
                    this.laber.attach_ids2=this.tenderPurchasePlan2.attachemeIds;
                    console.log(this.laber.attach_ids)
                    console.log(this.laber.attach_ids2)
                          laowushimingzhi.AddRealname(this.laber,this.projectId).then(()=>{
                              this.$message({ message: '添加成功',  type: 'success' });
                             if(this.laber.attach_ids != '' || this.laber.attach_ids != undefined){
                                  Laowuhetong.UpdateInfo(this.laber.attach_ids,sessionStorage.getItem('realName')).then(()=>{})
                              }
                              if(this.laber.attach_ids2 != '' || this.laber.attach_ids2 != undefined){
                                  Laowuhetong.UpdateInfo(this.laber.attach_ids2,sessionStorage.getItem('realName')).then(()=>{})
                              }
                          })
                
          }
          }
          }
          }
          }

      },



  
  },
  computed: {
            token: {
                get() {
                    return this.$store.state.token
                }
            },
            checkRoute(){
                return Object.keys(this.$route.params).length != 0
            }
        },
  created() {
       this.getprofessions();
  },
  
};
</script>

<style>
.divtable{
    border-collapse:collapse;
}
.divtable td{
    padding:10px;
    border:1px solid rgb(7, 136, 175);
}
.tabletd{
    text-align: right;
    background-color: rgb(113, 222, 241);
}
.color{
    background-color: rgb(113, 222, 241);
}
.divtable2{
    border-collapse:collapse;
}
.divtable2 td{
    padding:10px;
    border:1px solid rgb(7, 136, 175);
}
.td{
    text-align: center;
}
</style>